export default function (sphereDivCount) {
    let i = 0
    let ai = 0
    let si = 0
    let ci = 0
    let j = 0
    let aj = 0
    let sj = 0
    let cj = 0
    let p1 = 0
    let p2 = 0
    const positions = []
    const indices = []

    // Generate coordinates
    for (j = 0; j <= sphereDivCount; j++) {
        aj = j * Math.PI / sphereDivCount
        sj = Math.sin(aj)
        cj = Math.cos(aj)
        for (i = 0; i <= sphereDivCount; i++) {
            ai = i * 2 * Math.PI / sphereDivCount
            si = Math.sin(ai)
            ci = Math.cos(ai)
            positions.push(si * sj) // X
            positions.push(cj) // Y
            positions.push(ci * sj) // Z
        }
    }

    // Generate indices
    for (j = 0; j < sphereDivCount; j++) {
        for (i = 0; i < sphereDivCount; i++) {
            p1 = j * (sphereDivCount + 1) + i
            p2 = p1 + (sphereDivCount + 1)
            indices.push(p1)
            indices.push(p2)
            indices.push(p1 + 1)
            indices.push(p1 + 1)
            indices.push(p2)
            indices.push(p2 + 1)
        }
    }
    return { positions, indices }
}